var express = require('express');
var router = express.Router();
//导入连接mysql的函数，用于后于的mysql操作
const pool = require('../db/index')

//\* GET home page. \*//
router.get('/', function (req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('/api/getmaterialdata', (req, res, next) => {
  const parms = req.query;
  const data = {
    "csb1station1status": "正常",
    "csb1station2status": "待换料",
  };
  res.send({ status: 200, message: '请求数据成功', parms, data: data });
})

router.post('/dev-api/login', (req, res, next) => {
  const parms = req.body;
  const data = {
    "token": 12345678,
  };
  res.send({ status: 200, message: '请求数据成功', parms, data: data });
})

pool.getConnection(function(err, coon) {
  if (err) throw err; // not connected!
  router.get('/completionrate', (req, res, next) => {
    const parms = req.query;
    coon.query(`select date,production_processes,spotcheck_type,completion_rate from spotcheck_completion_rate
    where date='${parms.param1}' and production_processes='${parms.param2}'`, (err, data) => {
      if (err) res.send({ status: 300, message: '请求失败', err })
      res.send({ status: 200, message: '请求数据成功', parms, data: data })
    })
  })

  router.post('/eqpparam', (req, res, next) => {
    const parms = req.body;
    parms.collection_time=JSON.stringify(new Date(parms.collection_time))
    coon.query(`select value from eqp_params where eqp_code='${parms.eqp_code}' and parameter_code in (${parms.parameter_code})
    and DATE_FORMAT(datetime,'%Y-%m-%d %H:%i')=DATE_FORMAT(${parms.collection_time},'%Y-%m-%d %H:%i') order by seq`, (err, data) => {
      if (err) res.send({ status: 300, message: '请求失败', err })
      res.send({ status: 200, message: '请求数据成功', parms, data: data })
    })
  })

  router.get('/noproductiondate', (req, res, next) => {
    const parms = req.query;
    coon.query(`select date from production_plan where date like '${parms.month}%' and is_production='N'`, (err, data) => {
      if (err) res.send({ status: 300, message: '请求失败', err })
      res.send({ status: 200, message: '请求数据成功', parms, data: data })
    })
  })

  router.get('/getformtemplate', (req, res, next) => {
    const parms = req.query;
    if (parms.param1=='一次注液'){
      if (parms.param2=='电子秤测量记录表'){
        coon.query(`select inspection_content,frequency from electronic_scale_measurement_record_form_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else if (parms.param2=='清洁记录表'){
        coon.query(`select cleaning_content,cleaning_standards,cleaning_methods,frequency from 
        cleaning_record_form_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else if (parms.param2=='电子秤内部验证记录表'){
        coon.query(`select equipment_name,standard_value,allowable_error_value,frequency from 
        electronic_scale_internal_verification_record_form_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else if (parms.param2=='设备点检表'){
        coon.query(`select inspection_content,inspection_standards,inspection_method,frequency from 
        equipment_inspection_checklist_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else if (parms.param2=='工序点检表'){
        coon.query(`select inspection_items,inspection_standards,frequency,result from 
        process_inspection_checklist_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else{
        coon.query(`select serial_number,standard_value,allowable_error_value,frequency from 
        injection_pump_calibration_record_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
    }
    else if (parms.param1=='高温化成'){
      if (parms.param2=='清洁记录表(高温浸润)'){
        coon.query(`select cleaning_content,cleaning_standards,cleaning_methods,frequency from 
        hightemperature_infiltration_cleaning_record_form_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else if (parms.param2=='清洁记录表(化成)'){
        coon.query(`select cleaning_content,cleaning_standards,cleaning_methods,frequency from 
        chemical_cleaning_record_form_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else if (parms.param2=='工序点检表(化成)'){
        coon.query(`select inspection_items,inspection_standards,frequency,result from 
        chemical_process_inspection_checklist_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
      else {
        coon.query(`select inspection_content,inspection_standards,inspection_method,frequency from 
        chemical_equipment_inspection_checklist_template order by id`, (err, data) => {
          if (err) res.send({ status: 300, message: '请求失败', err })
          res.send({ status: 200, message: '请求数据成功', parms, data: data })
        })
      }
    }
  })

  router.get('/searchformdata', (req, res, next) => {
    const parms = req.query;
    if (parms.param4=='电子秤测量记录表'){
      coon.query(`select inspection_content,result from electronic_scale_measurement_record_form where date='${parms.param1}'
      and shift='${parms.param2}' and equipment='${parms.param3}' order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='清洁记录表'){
      coon.query(`select cleaning_content,cleaning_standards,cleaning_methods,frequency from cleaning_record_form
      where date='${parms.param1}' and shift='${parms.param2}' and equipment='${parms.param3}' order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='电子秤内部验证记录表'){
      coon.query(`select equipment_name,standard_value,allowable_error_value from electronic_scale_internal_verification_record_form
      where date='${parms.param1}' and shift='${parms.param2}' and equipment='${parms.param3}' order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='设备点检表'){
      coon.query(`select inspection_content,inspection_standards,inspection_method from equipment_inspection_checklist
      where date='${parms.param1}' and shift='${parms.param2}' and equipment='${parms.param3}' order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='工序点检表'){
      coon.query(`select inspection_items,inspection_standards,result from process_inspection_checklist
      where date='${parms.param1}' and shift='${parms.param2}' and equipment='${parms.param3}' order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='注液泵校准记录表'){
      coon.query(`select serial_number,standard_value,allowable_error_value from injection_pump_calibration_record
      where date='${parms.param1}' and shift='${parms.param2}' and equipment='${parms.param3}' order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }

    else if (parms.param4=='清洁记录表(高温浸润)'){
      coon.query(`select cleaning_content,cleaning_standards,cleaning_methods,frequency from 
      hightemperature_infiltration_cleaning_record_form_template order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='清洁记录表(化成)'){
      coon.query(`select cleaning_content,cleaning_standards,cleaning_methods,frequency from 
      chemical_cleaning_record_form_template order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='工序点检表(化成)'){
      coon.query(`select inspection_items,inspection_standards,frequency,result from 
      chemical_process_inspection_checklist_template order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
    else if (parms.param4=='设备点检表(化成)'){
      coon.query(`select inspection_content,inspection_standards,inspection_method,frequency from 
      chemical_equipment_inspection_checklist_template order by id`, (err, data) => {
        if (err) res.send({ status: 300, message: '请求失败', err })
        res.send({ status: 200, message: '请求数据成功', parms, data: data })
      })
    }
  })

  router.put('/updateformtemplate', (req, res, next) => {
    const parms = req.body;
    if (parms.param6=='电子秤测量记录表'){
      if (parms.param1!=null){
        coon.query(`update electronic_scale_measurement_record_form_template set Inspection_content='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param2!=null){
        coon.query(`update electronic_scale_measurement_record_form_template set frequency='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='清洁记录表'){
      if (parms.param1!=null){
        coon.query(`update cleaning_record_form_template set cleaning_content='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update cleaning_record_form_template set cleaning_standards='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update cleaning_record_form_template set cleaning_methods='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update cleaning_record_form_template set frequency='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='电子秤内部验证记录表'){
      if (parms.param1!=null){
        coon.query(`update electronic_scale_internal_verification_record_form_template set equipment_name='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update electronic_scale_internal_verification_record_form_template set standard_value='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update electronic_scale_internal_verification_record_form_template set allowable_error_value='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update electronic_scale_internal_verification_record_form_template set frequency='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='设备点检表'){
      if (parms.param1!=null){
        coon.query(`update equipment_inspection_checklist_template set inspection_content='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update equipment_inspection_checklist_template set inspection_standards='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update equipment_inspection_checklist_template set inspection_method='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update equipment_inspection_checklist_template set frequency='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='工序点检表'){
      if (parms.param1!=null){
        coon.query(`update process_inspection_checklist_template set inspection_items='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update process_inspection_checklist_template set inspection_standards='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update process_inspection_checklist_template set frequency='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update process_inspection_checklist_template set result='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='注液泵校准记录表'){
      if (parms.param1!=null){
        coon.query(`update injection_pump_calibration_record_template set serial_number='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update injection_pump_calibration_record_template set standard_value='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update injection_pump_calibration_record_template set allowable_error_value='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update injection_pump_calibration_record_template set frequency='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='清洁记录表(高温浸润)'){
      if (parms.param1!=null){
        coon.query(`update hightemperature_infiltration_cleaning_record_form_template set cleaning_content='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update hightemperature_infiltration_cleaning_record_form_template set cleaning_standards='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update hightemperature_infiltration_cleaning_record_form_template set cleaning_methods='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update hightemperature_infiltration_cleaning_record_form_template set frequency='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='清洁记录表(化成)'){
      if (parms.param1!=null){
        coon.query(`update chemical_cleaning_record_form_template set cleaning_content='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update chemical_cleaning_record_form_template set cleaning_standards='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update chemical_cleaning_record_form_template set cleaning_methods='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update chemical_cleaning_record_form_template set frequency='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='工序点检表(化成)'){
      if (parms.param1!=null){
        coon.query(`update chemical_process_inspection_checklist_template set inspection_items='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update chemical_process_inspection_checklist_template set inspection_standards='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update chemical_process_inspection_checklist_template set frequency='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update chemical_process_inspection_checklist_template set result='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
    if (parms.param6=='设备点检表(化成)'){
      if (parms.param1!=null){
        coon.query(`update chemical_equipment_inspection_checklist_template set inspection_content='${parms.param1}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param2!=null){
        coon.query(`update chemical_equipment_inspection_checklist_template set inspection_standards='${parms.param2}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      if (parms.param3!=null){
        coon.query(`update chemical_equipment_inspection_checklist_template set inspection_method='${parms.param3}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
      else if (parms.param4!=null){
        coon.query(`update chemical_equipment_inspection_checklist_template set frequency='${parms.param4}' where id=${parms.param5}`, (err, data) => {
          if (err) res.send({ status: 300, message: '更新失败', err })
          res.send({ status: 200, message: '更新数据成功', parms, data: data })
        })
      }
    }
  })

  //得到mysql数据库内的数据
router.get('/datas', (req, res, next) => {
  const parms = req.query;
  if (parms.starttime!=null && parms.endtime!=null){
    coon.query(`select insert_time,tbl_id,tbl_name from tbl_user where insert_time>='${parms.starttime}' 
      and insert_time<='${parms.endtime}'`, (err, data) => {
      if (err) res.send({ status: 400, message: '请求失败', err })
      res.send({ status: 300, message: '请求数据成功', parms, data: data })
    })
  }
  else{
    coon.query(`select insert_time,tbl_id,tbl_name from tbl_user`, (err, data) => {
      if (err) res.send({ status: 400, message: '请求失败', err })
      res.send({ status: 200, message: '请求数据成功', parms, data: data })
    })
  }
})
//oee数据查询
router.get('/oeedata', (req, res, next) => {
  const parms = req.query;
  if (parms.starttime!=null && parms.endtime!=null){
    const starttime=JSON.stringify(new Date(parms.starttime))
    const endtime=JSON.stringify(new Date(parms.endtime))
    if(!parms.selectdata){
      coon.query(`select equip_code,equip_status,start_timestamp,end_timestamp,last_time from oee_status_transform where 
        start_timestamp>=${starttime} and end_timestamp<=${endtime}`, (err, data) => {
        if (err) res.send({ status: 400, message: '请求失败', parms, err })
        else res.send({ status: 300, message: '请求数据成功', parms, starttime, endtime, data: data })
      })
    }
    if(parms.selectdata.length>0){
      coon.query(`select equip_code,equip_status,start_timestamp,end_timestamp,last_time from oee_status_transform where 
        start_timestamp>=${starttime} and end_timestamp<=${endtime} and equip_code in ('${parms.selectdata}')`, (err, data) => {
        if (err) res.send({ status: 500, message: '请求失败', parms, err })
        else res.send({ status: 400, message: '请求数据成功', parms, starttime, endtime, data: data })
      })
    }
  }
  else{
    coon.query(`select equip_code,equip_status,start_timestamp,end_timestamp,last_time from oee_status_transform`, (err, data) => {
      if (err) res.send({ status: 300, message: '请求失败', err })
      else res.send({ status: 200, message: '请求数据成功', data: data })
    })
  }
})
//添加用户
router.post('/adduser', (req, res, next) => {
  const parms = req.body
  //将数据导入mysql数据库的语句
  
  coon.query(`INSERT INTO tbl_user(tbl_id, tbl_name, tbl_age, tbl_sex) 
 VALUES
('${parms.id}','${parms.name}','${parms.age}','${parms.sex}')`, (err, data) => {
    if (err) {
      res.send({ code: 1,status: 300, message: "增添数据失败" }) 
      return
    }
    res.send({ code: 0, status: 200, message: '添加数据成功', data: data })
  })
})
//按照传入的id删除对应的一行数据
router.delete('/deluser/:id', (req, res, next) => {
  const parms = req.params
  //删除指定id对应行数据的mysql数据库的语句
  coon.query(`delete from tbl_user where tbl_user.tbl_id='${parms.id}'`, (err, data) => {
    if (err){
      res.send({ code: 1, message: "删除数据失败" })
      return
    } 
    res.send({ code: 1, status: 200, message: '删除数据成功', data: data })
  })
})
});
module.exports = router;

